import request from '@/utils/request'

// 新增分组
export function addBatch(params) {
  return request({
    url: `/online/management/admin/batch`,
    method: 'post',
    data: params
  })
}

// 新增分组
export function updateBatch(batchId, params) {
  return request({
    url: `/online/management/admin/batch/${batchId}`,
    method: 'post',
    data: params
  })
}

// 删除分组
export function delBatch(params) {
  return request({
    url: `/online/management/admin/batch/${params.batchId}`,
    method: 'delete'
  })
}

// 分组列表查询
export function queryBatchList(params) {
  return request({
    url: `/online/management/admin/batch/list`,
    method: 'get',
    params
  })
}

// 根据设备查询批次列表
export function queryBatchBySn(devSn) {
  return request({
    url: `/online/management/admin/batch/list/${devSn}`,
    method: 'get'
  })
}

// 分组列表分页查询
export function queryBatchByPage(params) {
  return request({
    url: `/online/management/admin/batch/batchs`,
    method: 'get',
    params
  })
}

// 分组详情查询
export function findBatchDetails(params) {
  return request({
    url: `/online/management/admin/batch/${params.batchId}/details`,
    method: 'get',
    params
  })
}

// 查询当前运营商是否支持flykey证书下发指令
export function isOpenFlykeyCertDownload() {
  return request({
    url: `/online/management/admin/batch/flykey/cert/download/config`,
    method: 'get'
  })
}

// 设备型号列表查询
export function findAllDeviceModel(params) {
  return request({
    url: `/online/management/admin/batch/list/device/model`,
    method: 'get',
    params
  })
}

// 分组内的终端列表分页查询
export function queryBatchDevicePage(params) {
  return request({
    url: `/online/management/admin/batch/${params.batchId}/device`,
    method: 'get',
    params
  })
}

// 分组内的操作列表分页查询
export function queryBatchOperationPage(params) {
  return request({
    url: `/online/management/admin/batch/${params.batchId}/operation`,
    method: 'get',
    params
  })
}

// 添加终端到分组（输入框方式）
export function addBatchDevice(params) {
  return request({
    url: `/online/management/admin/batch/${params.batchId}/device/${params.devSn}`,
    method: 'post',
    data: params
  })
}

// 添加终端到分组（输入框方式）
export function addBatchDeviceByTid(params) {
  return request({
    url: `/online/management/admin/batch/${params.batchId}/device/tid/${params.devTid}`,
    method: 'post',
    data: params
  })
}

// 添加终端到分组（终端页面勾选方式）
export function addBatchDeviceList(batchId, data) {
  return request({
    url: `/online/management/admin/batch/${batchId}/device/list`,
    method: 'post',
    data: data
  })
}

// 添加终端到分组（按文件导入）
export function addBatchDeviceByFile(params, data) {
  return request({
    url: `/online/management/admin/batch/${params.batchId}/device/file`,
    method: 'post',
    data: data,
    timeout: 1000 * 60 * 10
  })
}

// 添加终端到分组（按文件导入）
export function addBatchDeviceByApp(batchId, data) {
  return request({
    url: `/online/management/admin/batch/${batchId}/device/app`,
    method: 'post',
    data: data,
    timeout: 1000 * 60 * 10
  })
}



// 删除分组终端（终端页面勾选方式）
export function delBatchLegalDevices(params) {
  return request({
    url: `/online/management/admin/batch/${params.batchId}/device/list/del`,
    method: 'post',
    data: params
  })
}

// 从分组内删除终端（输入框方式）
export function delBatchDevice(params) {
  return request({
    url: `/online/management/admin/batch/${params.batchId}/device/${params.devSn}`,
    method: 'delete',
    params
  })
}

// 从分组内删除终端（输入框方式）Tid
export function delBatchDeviceByTid(params) {
  return request({
    url: `/online/management/admin/batch/${params.batchId}/device/tid/${params.devTid}`,
    method: 'delete',
    params
  })
}

// 从分组内删除终端（按文件）
export function delBatchDeviceByFile(params, data) {
  return request({
    url: `/online/management/admin/batch/${params.batchId}/device/file/del`,
    method: 'post',
    data: data,
    timeout: 1000 * 60 * 10
  })
}

// 分组内终端列表导出
export function exportBatchDevice(params) {
  return request({
    url: `/online/management/admin/batch/${params.batchId}/device/file/export`,
    method: 'get',
    params
  })
}

// 增加一条指令操作
export function addCmd(batchId, data) {
  return request({
    url: `/online/management/admin/batch/${batchId}/add/operation`,
    method: 'post',
    timeout: 20 * 60 * 1000,
    data
  })
}

// 增加一条卸载应用指令操作
export function uninstallApp(batchId, data) {
  return request({
    url: `/online/management/admin/batch/${batchId}/uninstall/app`,
    method: 'post',
    timeout: 20 * 60 * 1000,
    data
  })
}

// 分页查询指令执行的终端列表
export function cmd2DevicePage(cmdCode, params) {
  return request({
    url: `/online/management/admin/batch/command/${cmdCode}/devices`,
    method: 'get',
    params
  })
}

// 分页查询指令执行的终端列表
export function exportCmd2Device(cmdCode, params) {
  return request({
    url: ``,
    method: 'get',
    params
  })
}

// 分页查询分组操作的终端列表
export function operation2DevicePage(batchOperationId, params) {
  return request({
    url: `/online/management/admin/batch/${batchOperationId}/devices`,
    method: 'get',
    params
  })
}

export function cmdInfo(cmdCode) {
  return request({
    url: `/online/management/admin/batch/${cmdCode}/operation/info`,
    method: 'get'
  })
}

export function pushApp(batchId, appFileId) {
  return request({
    url: `/online/management/admin/batch/` + batchId + `/remote-ctl/app-install/` + appFileId,
    method: 'POST'
  })
}


export function pushFirm(batchId, appFileId, params) {
  return request({
    url: `/online/management/admin/batch/` + batchId + `/remote-ctl/firm-install/` + appFileId,
    method: 'POST',
    params
  })
}

export function setParams(batchId, data) {
  return request({
    url: `/online/management/admin/batch/${batchId}/remote-cli/params/system`,
    method: 'POST',
    data
  })
}

export function delBatchOperations(params) {
  return request({
    url: `/online/management/admin/batch/${params.batchId}/operation`,
    method: 'delete',
    data: params.batchOperationList
  })
}

export function switchGeoTrace(batchId, data) {
  return request({
    url: `/online/management/admin/batch/${batchId}/geo/trace/switch`,
    method: 'POST',
    params: data
  })
}

export function pauseCommand(cmdCode) {
  return request({
    url: `/online/management/admin/batch/command/${cmdCode}/pause`,
    method: 'POST'
  })
}

export function pauseCommandByDevice(cmdCode, devSn) {
  return request({
    url: `/online/management/admin/batch/command/${cmdCode}/pause/device/${devSn}`,
    method: 'POST'
  })
}

export function getModelAndDeviceFlagList(params) {
  return request({
    url: `/online/management/admin/batch/model-devflag`,
    method: 'get',
    params
  })
}

export function confirmImport(batchNo) {
  return request({
    url: `/online/management/estate/import/confirm/${batchNo}`,
    method: 'POST'
  })
}

export function confirmTransfer(batchNo) {
  return request({
    url: `/online/management/estate/transfer/confirm/${batchNo}`,
    method: 'POST'
  })
}

export function getBatchAppPage(params) {
  return request({
    url: '/online/management/admin/batch/apps',
    method: 'get',
    params
  })
}


